package com.mw.job.disruptor;

import com.lmax.disruptor.WorkHandler;
import com.mw.job.bean.DataBean;
import com.mw.job.context.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by mengdexuan on 2017/9/18 10:36.
 *
 * DataBean 消费者
 */
public class DisruptorConsumer implements WorkHandler<DataBean> {

	private static Logger log = LoggerFactory.getLogger(DisruptorConsumer.class);

	JdbcTemplate jdbcTemplate = SpringContextUtil.getBean(JdbcTemplate.class);


	@Override
	public void onEvent(DataBean event) throws Exception {

		Thread.sleep(1000*2);//模拟消费用时

		String table = "test";
		/*if (event.getId()==8){//构造一个异常
			table = "asdf";
		}*/


		jdbcTemplate.update("update "+table+" set status = 3 where id = "+ event.getId());


		log.info("消费数据(C) --> "+event);

	}
}
